package controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import service.StuManager;
import domain.User;

@Controller
public class StuManagerController {
	@Autowired(required=true)
//	@Resource(name="sm")
	private StuManager sm;

	/*public void setSm(StuManager sm) {
		this.sm = sm;
	}
	
	public StuManager getSm() {
		return sm;
	}*/

	@RequestMapping("/login")
	public String login(String xh,String psd,HttpServletRequest request){
		User u = sm.login(xh, psd);
		if(u != null){
			request.getSession().setAttribute("u", u);
			return "WEB-INF/jsp/loginSuc";
		}else{
			return "login";
		}


	}
	@RequestMapping("/regist")
	public String regist(User u,HttpServletRequest request){
		int rs = sm.regist(u);
		if(rs>0){
			return "redirect:/registSuc.jsp";//重定向？
		}else{
			return "regist";
		}
	}
}
